/*
 * inicializacion.h
 *
 *  Created on: 09/10/2011
 *      Author: Normandia
 *
 *  Funciones de inicializacion del Filesystem
 */

#ifndef INICIALIZACION_H_
#define INICIALIZACION_H_

#include <stdint.h>
#include <math.h>
#include "collections/queue.h"

#include "filesystem.h"
//#include "clusters.h"

// Registro del boot sector
typedef struct {
        uint8_t jmp[3];
        uint64_t oem;
        uint16_t n_bytes_per_sector;
        uint8_t n_sectors_per_cluster;
        uint16_t n_reserved_sector;
        uint8_t n_fat;
        uint16_t n_max_root_dir;
        uint16_t n_sectors;
        uint8_t d_media_desc;
        uint16_t n_sectors_per_fat_16;
        uint16_t n_sectors_per_track;
        uint16_t n_heads;
        uint32_t n_hidden_sectors;
        uint32_t n_sectors_ext;
        uint32_t n_sectors_per_fat;
        uint16_t fat_flags;
        uint16_t version;
        uint32_t n_cluster_root_dir;
        uint16_t n_sector_fs_info;
        uint16_t n_sector_copy_boot;
        uint8_t	reserved[12];
        uint8_t physical_drive_number;
        uint8_t reserved2;
        uint8_t ext_boot_signature;
        uint32_t serial_number;
        char volume_label[11];
        char fat_file_system_type[8];
        uint8_t	os_boot_code[420];
        uint16_t boot_sector_signature;
        uint32_t RRaA;
        uint8_t reserved3[480];
        uint32_t rrAa;
        uint32_t free_clusters;
        uint32_t ultimo_cluster_aloc;
        uint8_t reserved4[12];
        uint32_t AA;
}__attribute__((__packed__)) DISK_FORMAT;

// Funciones
void inicializarVarGlobales();
void leerBootSector();
void leerFat();
void ObtenerClusterLibres();

uint32_t* cache_fat;
DISK_FORMAT* cache_boot_sector;
t_queue *ptrListaSectLibre;
void agregarClusterLibre(uint32_t cluster);

#endif /* INICIALIZACION_H_ */
